
//
// 20120618 - (Bergen Off. Library) Created-
//

package org.soekrat.server.orbsuppliers;

import java.util.List;

import org.soekrat.environment.Orb;
import org.soekrat.environment.OrbSupplier;
import org.soekrat.environment.conversationbase.SoekratDatabase;
import org.soekrat.server.servlets.chat.ServerSoekratDatabase;

/**
 * <p>
 *   {@link OrbSupplier} that creates 
 *   {@link ServerSoekratDatabase} as the 
 *   {@link SoekratDatabase} put on the 
 *   {@link Orb} as attribute named {@code database}.
 * </p>
 * @author Arne Halvorsen (AH)
 * @author Laetitia Le Chatton (LLC)
 */
public final class ServerSoekratDatabaseOrbSupplier implements OrbSupplier 
{
  /**
   * <p>
   *   Constructor.
   * </p>
   */
  public ServerSoekratDatabaseOrbSupplier(){}

  // Specified in OrbSupplier.
  public String getEngineName(){ return null; }

  // Specified in OrbSupplier.
  public String supply(Orb orb, List<OrbSupplier> secondPass) 
  {
    Long folderId=orb.getLong("folder-id");
    if (folderId==null)
    {
      folderId=orb.getLong("rat-base-id");
      if (folderId==null)
      {
        return "ServerSoekratDatabaseOrbSupplier: "+
          "Missing rat-base-id orb attribute";
      }
    }
    
    SoekratDatabase sd=new ServerSoekratDatabase(folderId);
    
    orb.setAttribute("database", sd);
    
    return null;
  }
  
}
